home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’97 / Warrior’s Progress / source code / Source / Libraries / Trees / DowncastLoop.h < prev    next >
Encoding:
Text File  |  1997-06-28  |  2.7 KB  |  74 lines  |  [TEXT/CWIE]

  1. // DowncastLoop.h
  2.  
  3. #ifndef DowncastLoop_h
  4. #define DowncastLoop_h
  5.  
  6. template < class Inherited,
  7.               class HeadType,
  8.               class HeadBase,
  9.               class NodeType,
  10.               class NodeBase >
  11. class DowncastLoop: private Inherited
  12.   {
  13.     typedef ListLoop<Target> LoopType;
  14.     
  15.     private:
  16.         static const NodeType *DownCast( const NodeBase *n )
  17.           {
  18.             return static_cast< const NodeType* >( n );
  19.           }
  20.  
  21.         static const HeadType& DownCast( const HeadBase& n )
  22.           {
  23.             return static_cast< const HeadType& >( n );
  24.           }
  25.     
  26.     public:
  27.         DowncastLoop( const HeadType& h )                                        : Inherited( h )                    {}
  28.         DowncastLoop( const HeadType& h, AtStart )                            : Inherited( h, atStart )        {}
  29.         DowncastLoop( const HeadType& h, AtEnd )                                : Inherited( h, atEnd )            {}
  30.         DowncastLoop( const HeadType& h, Nowhere )                            : Inherited( h, nowhere )        {}
  31.         DowncastLoop( const HeadType& h, const NodeType& p )                : Inherited( h, p )                {}
  32.         DowncastLoop( const HeadType& h, Before, const NodeType& p )    : Inherited( h, before, p )    {}
  33.         DowncastLoop( const HeadType& h, After, const NodeType& p )        : Inherited( h, after, p )        {}
  34.         DowncastLoop( const HeadType& h, BeforeStart )                        : Inherited( h, beforeStart )    {}
  35.         DowncastLoop( const HeadType& h, AfterEnd )                            : Inherited( h, afterEnd )        {}
  36.         
  37.         const HeadType& Owner() const                        { return DownCast( Inherited::Owner() ); }
  38.         
  39.         Inherited::Finished;
  40.         Inherited::Unfinished;
  41.  
  42.         Inherited::MoveToFinish;
  43.         Inherited::MoveToFirst;
  44.         Inherited::MoveToLast;
  45.         Inherited::MoveBeforeFirst;
  46.         Inherited::MoveAfterLast;
  47.         
  48.         void MoveTo( const NodeType& p )                    { Inherited::MoveTo( p ); }
  49.         void MoveBefore( const NodeType& p )            { Inherited::MoveBefore( p ); }
  50.         void MoveAfter( const NodeType& p )                { Inherited::MoveAfter( p ); }
  51.                     
  52.         bool operator==( const LoopType& r ) const    { return Inherited::operator==( r ); }
  53.         bool operator!=( const LoopType& r ) const    { return Inherited::operator!=( r ); }
  54.  
  55.         bool operator==( const NodeType& r ) const    { return Inherited::operator==( r ); }
  56.         bool operator!=( const NodeType& r ) const    { return Inherited::operator!=( r ); }
  57.             
  58.         Inherited::Null;
  59.         const LinkType *Position() const        { return DownCast( Inherited::Position() ); }
  60.         
  61.         const NodeType *Next() const            { return DownCast( Inherited::Next() ); }
  62.         const NodeType *Previous() const        { return DownCast( Inherited::Previous() ); }
  63.         
  64.         const NodeType& operator*() const    { return *DownCast( Inherited::operator->() ); }
  65.         const NodeType *operator->() const    { return DownCast( Inherited::operator->() ); }
  66.         
  67.         void operator++()                            { Inherited::operator++(); }
  68.         void operator++(int)                        { Inherited::operator++(0); }
  69.         void operator--()                            { Inherited::operator--(); }
  70.         void operator--(int)                        { Inherited::operator--(0); }
  71.   };
  72.  
  73. #endif
  74.